//
//  CMDBHomeTopicTableView.swift
//  CMDB
//
//  Created by 曹桂祥 on 17/4/9.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

private let TopicCellID = "TopicCellID"

class CMDBHomeTopicTableView: CMDBRefreshTableView,FYSliderViewCustomizable {
    
    private lazy var headerView: CMDBBaseView = CMDBBaseView.getInstnce(CGRect(x: 0, y: 0, width: CMDB_Screen_Width, height: CMDB_Screen_Width * 1 / 3))
    
    private lazy var sliderView:FYSliderView  = {
        
        var sliderView = FYSliderView(frame: CGRect(x: 0, y: 0, width: CMDB_Screen_Width, height: CMDB_Screen_Width * 1 / 3),option:self)
        
        return sliderView
        
    }()

    
    var controller : UIViewController?
    
    func updateBannerData(data: [CMDBADBean]) {
        
        if data.count > 0 {
            
            sliderView.delegate              = self
            
            self.sliderView.imageObjectGroup = data
            
            headerView.addSubview(sliderView)
            
            self.tableHeaderView             = headerView
            
        }
        
    }

    
    override func setupTableView() {
        super.setupTableView()
        
        self.registerClass(CMDBHomeTrendTopicCell.self, forCellReuseIdentifier:TopicCellID)
    }
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        return dequeCellAndLoadContentFromAdapter(tableViewAdapterArray![indexPath.row] , indexPath: indexPath, tableView: self, controller: self.controller,cellReuseIdentifier : TopicCellID)
        
    }
    
    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        
        let viewModel = tableViewdataArray![indexPath.row] as! CMDBDynamicBean
        
        return viewModel.cellHeight
    }
    
}


//MARK:- banner点击事件的监听
extension CMDBHomeTopicTableView:FYSliderViewDelegate{
    func sliderView(didScrollToIndex index: Int) {
//        printLog("\(index)")
    }
    
    func sliderView(didSelectItemAtIndex index: Int) {
        let bannerObj = self.sliderView.imageObjectGroup[index]
//        mDelegate?.onItemClickType!("Banner", data: bannerObj, indexPath: nil)
//        printLog(index)
    }
}
